﻿using System.Collections.Generic;
using Bintje.bintje;
using System;
namespace Bintje
{
    public class Image :RepoObject
    {
        #region Fields

        private IList<Annotation> m_annotations;
        private string m_fileName;
        private int m_height;
        private byte[] m_imageData;
        private int m_locationId;
        private int m_userId;
        private int m_width;
        private string m_imageUrl;
        private bool m_imageDb;
        private string m_altitude;
        private long m_created1;
        private string m_latitude;
        private string m_longitude;
        private long m_modified1;

        #endregion
        
        #region Properties

        public int Width
        {
            get { return m_width; }
            set { m_width = value; }
        }

        public int UserId
        {
            get { return m_userId; }
            set { m_userId = value; }
        }

        public int LocationId
        {
            get { return m_locationId; }
            //set { m_locationId = value; }
        }

        public byte[] ImageData
        {
            get { return m_imageData; }
            set { m_imageData = value; }
        }

        public int Height
        {
            get { return m_height; }
            set { m_height = value; }
        }

        public string FileName
        {
            get { return m_fileName; }
            set { m_fileName = value; }
        }

        public IList<Annotation> Annotations
        {
            get { return m_annotations; }
            set { m_annotations = value; }
        }

        public string Url 
        {
            get { return m_imageUrl; }
        }

        public bool ImageDb
        {
            get { return m_imageDb; }
            set { m_imageDb = value; }
        }

        public string Latitude
        {
            get { return m_latitude; }
            set { m_latitude = value; }
        }

        public string Longitude
        {
            get { return m_longitude; }
            set { m_longitude = value; }
        }

        public long Created1
        {
            get { return m_created1; }
            set { m_created1 = value; }
        }

        public string Altitude
        {
            get { return m_altitude; }
            set { m_altitude = value; }
        }

        public long Modified1
        {
            get { return m_modified1; }
            set { m_modified1 = value; }
        }

        #endregion

        #region ctor

        public Image()
        {
            m_imageUrl = string.Empty;
        }

        public Image(image image)
        {
            if (null != image.annotations && image.annotations.Length > 0)
            {
                m_annotations = new List<Annotation>();
                for (int i = 0; i < image.annotations.Length; i++)
                {
                    m_annotations.Add(new Annotation(image.annotations[i]));
                }
            }

            m_fileName = image.fileName;
            m_height = image.height;
            m_id = image.id;
            m_imageData = image.imagedata;
            m_locationId = image.locationId;
            m_userId = image.userId;
            m_width = image.width;
            m_imageUrl = string.Empty;
            m_imageDb = image.imageDb;
        }

        public Image(image image, string url)
        {
            if (null != image.annotations && image.annotations.Length > 0)
            {
                m_annotations = new List<Annotation>();
                for (int i = 0; i < image.annotations.Length; i++)
                {
                    m_annotations.Add(new Annotation(image.annotations[i]));
                }
            }

            m_fileName = image.fileName;
            m_height = image.height;
            m_id = image.id;
            m_imageData = image.imagedata;
            m_locationId = image.locationId;
            m_userId = image.userId;
            m_width = image.width;
            m_imageUrl = url;
            m_imageDb = image.imageDb;
        }

        #endregion

        #region Methods

        internal image ConvertToAPI()
        {
            image img = new image();

            if (null != this.Annotations && this.Annotations.Count > 0)
            {
                img.annotations = Annotation.ConvertToAPI(this.Annotations);
            }
            img.fileName = this.FileName;
            img.height = this.Height;
            img.id = this.Id;
            img.imagedata = this.ImageData;
            img.locationId = this.LocationId;
            img.userId = this.UserId;
            img.width = this.Width;
            img.imageDb = this.ImageDb;

            return img;
        }

        internal static image[] ConvertToAPI(IList<Image> imagesList)
        {
            image[] images = (image[])Array.CreateInstance(typeof(image), imagesList.Count);
            for (int i = 0; i < imagesList.Count; i++)
            {
                images[i] = imagesList[i].ConvertToAPI();
            }
            return images;
        } 

        #endregion

        

        
    }
}
